#!/usr/bin/env bash

# Safety first
set -o errexit -o pipefail -o nounset
# Change into the project's directory
cd "$(dirname "$0")/.."

# Set defaults
reload=false

# Parse arguments
for i in "$@"; do
  case $i in
    --reload)
      reload=true
      shift
      ;;
    --*)
      echo "Unknown option $i"
      exit 1
      ;;
    *)
      ;;
  esac
done

# Serve the documentation
if [ "${reload}" = true ]; then
  poetry run sphinx-autobuild --open-browser --delay 0 --port 8145 docs docs/_build
else
  poetry run sphinx-build -b html docs docs/_build
fi
